/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameCheque.java
 *
 * Created on 13/09/2011, 21:18:57
 */
package br.com.GUI.cadastro;

import br.com.classes.Cheque;
import br.com.classes.Entidade;
import br.com.dao.ChequeDao;
import br.com.dao.EntidadeDao;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Kauane
 */
public class FrameCheque extends javax.swing.JFrame {

    int num;
    int cod_cheque;
    int variavelglobal = 0;
    String ControlAlteraCadastra = "1"; //Variavel que controla o funcionamento do botão alterar
    
    

    /** Creates new form FrameCheque */
    public FrameCheque() {
        initComponents();
        CarregarCheque();
        CarregarEntidade();
        jTableConsultaCheque.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
        jButtonAlterar.setEnabled(false);
    }
     
     public class LetraMaiuscul extends PlainDocument {  
     @Override  
     public void insertString(int offset, String str, AttributeSet attr)  
     throws BadLocationException {  
     super.insertString(offset, str.toUpperCase(), attr);  
     }    
}  

    public void CarregarCheque() {
        
        ChequeDao cdao = new ChequeDao();
       SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");   //converte para a data normal
       SimpleDateFormat formatoBanco = new SimpleDateFormat("yyyy-MM-dd");  // converte para a data do banco
        List<Cheque> lista = cdao.ListarCheque();
        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCheque.getModel();
        modelo.setRowCount(0);

        for (Cheque cx : lista) {
            String data = cx.getData();

            try {
                Date dataformatada; 
                dataformatada = formatoBanco.parse(data);
                String datafor = formato.format(dataformatada); 
                modelo.addRow(new Object[]{cx.getCod_cheque(), cx.getEntrada_ck(), cx.getSaida_ck(), cx.getBanco(), cx.getAgencia(), cx.getConta(), cx.getNum_cheque(), datafor, cx.getDevolvido(), cx.getValor_cheque(), cx.getEmitente()});
       } catch (ParseException ex) {
                Logger.getLogger(FrameCheque.class.getName()).log(Level.SEVERE, null, ex);
            }  
            }
        jTableConsultaCheque.setModel(modelo);
    }
    
    public void CarregarEntidade() {
        EntidadeDao edao = new EntidadeDao();
        List<Entidade> list1 = edao.ListarEntidade();
        DefaultTableModel modelo1 = (DefaultTableModel) jTable7.getModel();
        modelo1.setRowCount(0);

        for (Entidade e : list1) {

            modelo1.addRow(new Object[]{e.getCod_ent(), e.getNome_ent(), e.getEnd(), e.getTelefone(), e.getBairro(), e.getObs()});
        }
        jTable7.setModel(modelo1);
    }
    

    public void BuscarLimiteProximo() {
        num = num + 10;

        ChequeDao bdao = new ChequeDao();
        List<Cheque> lista = bdao.BuscarLimiteCheque(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCheque.getModel();
        modelo.setRowCount(0);

        for (Cheque c : lista) {
            modelo.addRow(new Object[]{c.getCod_cheque(), c.getAgencia(), c.getConta(), c.getNum_cheque(), c.getBanco(), c.getDevolvido(), c.getValor_cheque()});
        }

        jTableConsultaCheque.setModel(modelo);
                            if(lista.size()<10){
    jButtonAvancar.setEnabled(false);
    }   
        
    }

    public void BuscarLimiteAnterior() {
        num = num - 10;

        ChequeDao bdao = new ChequeDao();
        List<Cheque> lista = bdao.BuscarLimiteCheque(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCheque.getModel();
        modelo.setRowCount(0);

        for (Cheque c : lista) {
            modelo.addRow(new Object[]{c.getCod_cheque(), c.getAgencia(), c.getConta(), c.getNum_cheque(), c.getBanco(), c.getDevolvido(), c.getValor_cheque()});
        }
        jTableConsultaCheque.setModel(modelo);
       if(lista.size()<10){
    jButtonVoltar.setEnabled(false);
         }
    }

    public void CarregarLetraCheque() {
        String caixa = jTextFieldPesquisar.getText();

        ChequeDao cdao = new ChequeDao();
        List<Cheque> lista = cdao.ProcurarChequeLetra(caixa);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCheque.getModel();
        modelo.setRowCount(0);

        for (Cheque cx : lista) {
            modelo.addRow(new Object[]{cx.getCod_cheque(), cx.getBanco(), cx.getAgencia(), cx.getConta(), cx.getNum_cheque(), cx.getDevolvido(), cx.getValor_cheque()});
        }
        jTableConsultaCheque.setModel(modelo);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialogEntidade = new javax.swing.JDialog();
        jLabel16 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextFieldDialog = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTable7 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabelComp = new javax.swing.JLabel();
        jLabelBanco = new javax.swing.JLabel();
        jLabelAgencia = new javax.swing.JLabel();
        jLabelConta = new javax.swing.JLabel();
        jLabelNumCheque = new javax.swing.JLabel();
        jLabelOrigem = new javax.swing.JLabel();
        jLabelDevolvido = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jTextFieldComp = new javax.swing.JTextField();
        jTextFieldBanco = new javax.swing.JTextField();
        jTextFieldAgencia = new javax.swing.JTextField();
        jTextFieldConta = new javax.swing.JTextField();
        jTextFieldNumCheque = new javax.swing.JTextField();
        jTextFieldEmitente = new javax.swing.JTextField();
        jLabelValor = new javax.swing.JLabel();
        jLabelData = new javax.swing.JLabel();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jMoneyFieldChequeCadastro = new br.com.GUI.caixa.JMoneyField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableConsultaCheque = new javax.swing.JTable();
        jButton8 = new javax.swing.JButton();
        jButtonExcluir = new javax.swing.JButton();
        jButtonEditar = new javax.swing.JButton();
        jButtonVoltar = new javax.swing.JButton();
        jButtonAvancar = new javax.swing.JButton();
        jLabelPesquisar = new javax.swing.JLabel();
        jTextFieldPesquisar = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabelCheque = new javax.swing.JLabel();
        jButtonAlterar = new javax.swing.JButton();

        jDialogEntidade.setMinimumSize(new java.awt.Dimension(875, 320));

        jLabel16.setText("Pesquisa");

        jButton1.setText("ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Voltar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Novo");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jTable7.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome", "Endereço", "Telefone", "Bairro", "Limite", "Obs."
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable7MouseClicked(evt);
            }
        });
        jScrollPane7.setViewportView(jTable7);

        jButton2.setText("Atualizar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialogEntidadeLayout = new javax.swing.GroupLayout(jDialogEntidade.getContentPane());
        jDialogEntidade.getContentPane().setLayout(jDialogEntidadeLayout);
        jDialogEntidadeLayout.setHorizontalGroup(
            jDialogEntidadeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogEntidadeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialogEntidadeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDialogEntidadeLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldDialog, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jDialogEntidadeLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 820, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jDialogEntidadeLayout.setVerticalGroup(
            jDialogEntidadeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogEntidadeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialogEntidadeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldDialog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jDialogEntidadeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setTitle("Cadastro de Cheque");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Cheque"));

        jLabelComp.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelComp.setText("*Comp:");

        jLabelBanco.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelBanco.setText("*Banco:");

        jLabelAgencia.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelAgencia.setText("*Agência:");

        jLabelConta.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelConta.setText("*Conta:");

        jLabelNumCheque.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelNumCheque.setText("*Cheque Nº:");

        jLabelOrigem.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelOrigem.setText("*Emitente:");

        jLabelDevolvido.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelDevolvido.setText("*Devolvido:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Não", "Sim" }));

        jTextFieldComp.setDocument(new LetraMaiuscul());
        jTextFieldComp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCompActionPerformed(evt);
            }
        });

        jTextFieldBanco.setDocument(new LetraMaiuscul());

        jLabelValor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelValor.setText("*Valor:");

        jLabelData.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelData.setText("*Data:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelConta)
                            .addComponent(jLabelComp))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldConta, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                            .addComponent(jTextFieldComp))
                        .addGap(17, 17, 17)
                        .addComponent(jLabelBanco))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelOrigem)
                            .addComponent(jLabelValor))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jMoneyFieldChequeCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelNumCheque)
                                    .addComponent(jLabelData))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldBanco)
                                    .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                                    .addComponent(jTextFieldNumCheque))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelDevolvido)
                                    .addComponent(jLabelAgencia))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jTextFieldEmitente))))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelComp)
                    .addComponent(jTextFieldComp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelBanco)
                    .addComponent(jTextFieldBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelAgencia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelDevolvido)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelConta)
                        .addComponent(jTextFieldConta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelNumCheque)
                        .addComponent(jTextFieldNumCheque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelValor)
                        .addComponent(jLabelData)
                        .addComponent(jMoneyFieldChequeCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelOrigem)
                    .addComponent(jTextFieldEmitente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTableConsultaCheque.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Mov Origem", "Mov Destino", "Banco", "Agência", "Conta", "Cheque Nº", "Data", "Devolvido", "Valor", "Emitente"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableConsultaCheque.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTableConsultaCheque);
        jTableConsultaCheque.getColumnModel().getColumn(0).setMinWidth(50);
        jTableConsultaCheque.getColumnModel().getColumn(0).setPreferredWidth(50);
        jTableConsultaCheque.getColumnModel().getColumn(0).setMaxWidth(50);
        jTableConsultaCheque.getColumnModel().getColumn(1).setMinWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(1).setPreferredWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(1).setMaxWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(3).setMinWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(3).setPreferredWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(3).setMaxWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(8).setMinWidth(70);
        jTableConsultaCheque.getColumnModel().getColumn(8).setPreferredWidth(70);
        jTableConsultaCheque.getColumnModel().getColumn(8).setMaxWidth(70);
        jTableConsultaCheque.getColumnModel().getColumn(10).setMinWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(10).setPreferredWidth(80);
        jTableConsultaCheque.getColumnModel().getColumn(10).setMaxWidth(80);

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh.png"))); // NOI18N
        jButton8.setBorder(null);
        jButton8.setContentAreaFilled(false);
        jButton8.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh[2]over.png"))); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButtonExcluir.setBackground(null);
        jButtonExcluir.setForeground(null);
        jButtonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5].png"))); // NOI18N
        jButtonExcluir.setBorder(null);
        jButtonExcluir.setBorderPainted(false);
        jButtonExcluir.setContentAreaFilled(false);
        jButtonExcluir.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5]over.png"))); // NOI18N
        jButtonExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirActionPerformed(evt);
            }
        });

        jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png"))); // NOI18N
        jButtonEditar.setBorder(null);
        jButtonEditar.setContentAreaFilled(false);
        jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png"))); // NOI18N
        jButtonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarActionPerformed(evt);
            }
        });

        jButtonVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2].png"))); // NOI18N
        jButtonVoltar.setBorder(null);
        jButtonVoltar.setContentAreaFilled(false);
        jButtonVoltar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2]over.png"))); // NOI18N
        jButtonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVoltarActionPerformed(evt);
            }
        });

        jButtonAvancar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2].png"))); // NOI18N
        jButtonAvancar.setBorder(null);
        jButtonAvancar.setContentAreaFilled(false);
        jButtonAvancar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2]over.png"))); // NOI18N
        jButtonAvancar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAvancarActionPerformed(evt);
            }
        });

        jLabelPesquisar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelPesquisar.setText("Pesquisa");

        jTextFieldPesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldPesquisarKeyReleased(evt);
            }
        });

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/search[1].png"))); // NOI18N

        jLabelCheque.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelCheque.setText("Cheque");

        jButtonAlterar.setText("Alterar");
        jButtonAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabelCheque)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelPesquisar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jLabel13))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonVoltar)
                        .addGap(10, 10, 10)
                        .addComponent(jButtonEditar)
                        .addGap(12, 12, 12)
                        .addComponent(jButton8)
                        .addGap(10, 10, 10)
                        .addComponent(jButtonExcluir)
                        .addGap(10, 10, 10)
                        .addComponent(jButtonAvancar)
                        .addGap(117, 117, 117)
                        .addComponent(jButtonAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelCheque)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelPesquisar)
                            .addComponent(jTextFieldPesquisar))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonVoltar)
                    .addComponent(jButtonEditar)
                    .addComponent(jButton8)
                    .addComponent(jButtonExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButtonAlterar)
                        .addComponent(jButtonAvancar)))
                .addGap(11, 11, 11)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        CarregarCheque();
        jButtonAvancar.setEnabled(true);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButtonExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirActionPerformed
 if (jTableConsultaCheque.getSelectedRow() >= 0) {
        int linha = jTableConsultaCheque.getSelectedRow();

        Object[] OPTIONS = {"Sim", "Não"};
        int nome_cheque = Integer.parseInt(jTableConsultaCheque.getValueAt(linha, 0).toString());

        ChequeDao cdao = new ChequeDao();


        try {
            int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja excluir o registro?", "Excluir", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
            if (I == JOptionPane.YES_OPTION) {
                cdao.DeletarCheque(nome_cheque);
                JOptionPane.showMessageDialog(this, "Excluído com sucesso!");
                CarregarCheque();
            }
        } catch (Exception ex) {
            System.out.println("1 - " + ex.getMessage());
        } }else {
           JOptionPane.showMessageDialog(null, "Por favor selecione um cheque para ser excluido!");
       }      
    }//GEN-LAST:event_jButtonExcluirActionPerformed

    private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditarActionPerformed

        if (jTableConsultaCheque.getSelectedRow() >= 0) { // Caso nao tenha sido selecionado nada na tabela da um aviso de erro
            if (jLabelCheque.getText().equals("Cheque")) { //se for 1 estamos no cadastra se 2 no editar
                jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));

                try {

                    int k = jTableConsultaCheque.getSelectedRow();
                    cod_cheque = (Integer) jTableConsultaCheque.getValueAt(k, 0);
                    ChequeDao edao = new ChequeDao();
                    Cheque e = edao.PesquisarCheque(cod_cheque);// funcao que pesquisa os cheques
                    SimpleDateFormat formatbanco = new SimpleDateFormat("yyyy-MM-dd"); //mascara para a data do banco
                    SimpleDateFormat formato = new SimpleDateFormat("dd-MM-yyyy"); //mascara para a data normal
                    String databd = e.getData();
                    Date data = formatbanco.parse(databd);
                    jTextFieldComp.setText(e.getComp());
                    jTextFieldBanco.setText(e.getBanco());
                    jTextFieldAgencia.setText(e.getAgencia());
                   
                    jTextFieldConta.setText(e.getConta());
                 
                    jTextFieldNumCheque.setText(e.getNum_cheque());
                    jMoneyFieldChequeCadastro.setText(e.getValor_cheque().toString());
                    //jTextFieldValor.setText(e.getValor_cheque() + "");
                    jDateChooser1.setDate(data);
                    jTextFieldEmitente.setText(e.getEmitente());
                    if (e.getDevolvido().equals("Sim")) {
                        jComboBox1.setSelectedIndex(1);
                    } else {
                        jComboBox1.setSelectedIndex(0);
                    }
                    //   ControlAlteraCadastra = "2"; // seta 2 pq estamos com o alterar habilitado
                    jLabelCheque.setText("Alterar Cheque");
                  
                } catch (ParseException ex) {
                    Logger.getLogger(FrameCheque.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {

                jTextFieldComp.setText("");
                jTextFieldBanco.setText("");
                jTextFieldAgencia.setText("");
           
                jTextFieldConta.setText("");
               
                jTextFieldNumCheque.setText("");
                jMoneyFieldChequeCadastro.setText("");
               // jTextFieldValor.setText("");
                jDateChooser1.setDate(null);
                jTextFieldEmitente.setText("");
               
                jLabelCheque.setText("Cheque");
              

                jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
            }
        } else {
            JOptionPane.showMessageDialog(this, "Favor selecionar o Cheque para ser alterado!");
        }
    }//GEN-LAST:event_jButtonEditarActionPerformed

    private void jButtonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVoltarActionPerformed
       BuscarLimiteAnterior();
       jButtonAvancar.setEnabled(true);
}//GEN-LAST:event_jButtonVoltarActionPerformed

    private void jButtonAvancarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAvancarActionPerformed
        BuscarLimiteProximo();
        jButtonVoltar.setEnabled(true);
    }//GEN-LAST:event_jButtonAvancarActionPerformed

    private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField11ActionPerformed
         
    }//GEN-LAST:event_jTextField11ActionPerformed

    private void jTextFieldCompActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCompActionPerformed
         
    }//GEN-LAST:event_jTextFieldCompActionPerformed

    private void jTextFieldPesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldPesquisarKeyReleased
 
        CarregarLetraCheque();
    }//GEN-LAST:event_jTextFieldPesquisarKeyReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         
        if (variavelglobal == 1) {
               
            jTextFieldEmitente.setText(jTextFieldDialog.getText());
            jDialogEntidade.setVisible(false);
          
        
    } else {

          
            jDialogEntidade.setVisible(false);

        }
    
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
         
    jDialogEntidade.setVisible(false);
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
         
        FrameEntidade fm = new FrameEntidade();
        fm.setVisible(true);
}//GEN-LAST:event_jButton4ActionPerformed

    private void jTable7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable7MouseClicked
         
        if (variavelglobal == 1) {

        int VarTemp;

        int k = jTable7.getSelectedRow();
        VarTemp = (Integer) jTable7.getValueAt(k, 0);
        if (evt.getClickCount() == 1) {
            jTextFieldDialog.setText(Integer.toString(VarTemp));
        } else if (evt.getClickCount() == 2) {
            jTextFieldEmitente.setText(Integer.toString(VarTemp));
            jDialogEntidade.setVisible(false);
        
        }
    } else {
        int VarTemp;

        int k = jTable7.getSelectedRow();
        VarTemp = (Integer) jTable7.getValueAt(k, 0);
        if (evt.getClickCount() == 1) {
            jTextFieldDialog.setText(Integer.toString(VarTemp));
        } else if (evt.getClickCount() == 2) {
          
             jDialogEntidade.setVisible(false);
        }
    }
}//GEN-LAST:event_jTable7MouseClicked

        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
             
            CarregarEntidade();
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButtonAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarActionPerformed
         
        
    }//GEN-LAST:event_jButtonAlterarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrameCheque().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButtonAlterar;
    private javax.swing.JButton jButtonAvancar;
    private javax.swing.JButton jButtonEditar;
    private javax.swing.JButton jButtonExcluir;
    private javax.swing.JButton jButtonVoltar;
    private javax.swing.JComboBox jComboBox1;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JDialog jDialogEntidade;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabelAgencia;
    private javax.swing.JLabel jLabelBanco;
    private javax.swing.JLabel jLabelCheque;
    private javax.swing.JLabel jLabelComp;
    private javax.swing.JLabel jLabelConta;
    private javax.swing.JLabel jLabelData;
    private javax.swing.JLabel jLabelDevolvido;
    private javax.swing.JLabel jLabelNumCheque;
    private javax.swing.JLabel jLabelOrigem;
    private javax.swing.JLabel jLabelPesquisar;
    private javax.swing.JLabel jLabelValor;
    private br.com.GUI.caixa.JMoneyField jMoneyFieldChequeCadastro;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTable jTable7;
    private javax.swing.JTable jTableConsultaCheque;
    private javax.swing.JTextField jTextFieldAgencia;
    private javax.swing.JTextField jTextFieldBanco;
    private javax.swing.JTextField jTextFieldComp;
    private javax.swing.JTextField jTextFieldConta;
    private javax.swing.JTextField jTextFieldDialog;
    private javax.swing.JTextField jTextFieldEmitente;
    private javax.swing.JTextField jTextFieldNumCheque;
    private javax.swing.JTextField jTextFieldPesquisar;
    // End of variables declaration//GEN-END:variables
}
